import requests
from requests.auth import HTTPBasicAuth

# url = 'http://127.0.0.1:8000/admin/'
# # 默认可以重定向 allow_redirects = True
# # 返回的是重定向后的登录页面
# response = requests.get(url)
# print(response.status_code)
# print(response.headers.get('location'))


# url = 'http://127.0.0.1:8000/admin/'
# response = requests.get(url, allow_redirects=False)
# print(response.status_code)
# print(response.headers.get('location'))
#
# location = response.headers.get('location')
# location = f"http://127.0.0.1:8000{location}"
# response = requests.get(location)
# print(response.status_code)
# print(response.text)


# url = 'http://127.0.0.1:8000/admin/'
# headers={
#     # 携带cookie
#     'cookie':'sessionid=x1l9o87jf9fheqs0om7hgk8jzbgvkcuj'
# }
# cookies = {
#     'sessionid':'x1l9o87jf9fheqs0om7hgk8jzbgvkcuj'
# }
# response = requests.get(url, cookies=cookies)
# print(response.status_code)
# print(response.text)


# url = 'http://127.0.0.1:8000/admin/'
# headers={
#     # 携带cookie
#     'cookie':'sessionid=x1l9o87jf9fheqs0om7hgk8jzbgvkcuj'
# }
# cookies = {
#     'sessionid':'x1l9o87jf9fheqs0om7hgk8jzbgvkcuj'
# }
# response = requests.get(url, auth=HTTPBasicAuth('admin', '123456'))
# print(response.status_code)
# print(response.text)






